﻿Imports System.IO

Public Class Backup

    Public Shared Sub MaakBackup()
        Try
            Dim filePath As String = Application.StartupPath & "/App_Data/fairshop.mdb"
            Dim backupPath As String = String.Format("{0}/App_Data/backups/{1}fairshop.mdb", Application.StartupPath, DateTime.Now.ToString("yyMMddHHmmss"))
            If (Utility.IsOefenVersie()) Then
                filePath = Application.StartupPath & "/App_Data/fairshopOefen.mdb"
                backupPath = String.Format("{0}/App_Data/backups/{1}fairshopOefen.mdb", Application.StartupPath, DateTime.Now.ToString("yyMMddHHmmss"))
            End If
            Dim backupFile As New FileInfo(backupPath)
            If (Not backupFile.Directory.Exists()) Then
                backupFile.Directory.Create()
            End If
            File.Copy(filePath, backupPath)
            log.WriteInfo("Back-up gemaakt van " & filePath & " op " & backupPath)
        Catch ex As Exception
            log.WriteError("MaakBackup" & Environment.NewLine & ex.ToString())
        End Try
    End Sub


End Class
